package com.heo.protocol.packet;

import org.apache.log4j.Logger;

import com.heo.pub.DictEnum;
import com.heo.util.ByteHelper;
import com.heo.util.TimeHelper;

public class LoginResp extends BasePacket
{
  private int BODY_LENGTH = 10;// 包体长10个字节

  private static final String PACKET_NAME = "[登录应答包]";

  private static Logger log = Logger.getLogger(LoginResp.class);

  private byte loginResult = DictEnum.LoginResult.USERNAME_OR_PASSWORD_ERROR;// 登录结果
  private byte debugMode = 0x01;// 调试模式
  private int serverTime = TimeHelper.getCurrSecond();// 服务器时间戳
  private String serverVer = "1.00";

  public LoginResp(String logHeader, SocketPacket packet) throws Exception
  {
    super.copyPacket(logHeader, PACKET_NAME, packet);
  }

  public LoginResp() throws Exception
  {
    super(PACKET_NAME);
  }

  @Override
  public int getTotalLength()
  {
    return super.HEAD_LENGTH + BODY_LENGTH;
  }

  public LoginResp(byte loginResult, byte debugMode, String devicePass, int serverTime, short sequenceId) throws Exception
  {
    this.loginResult = loginResult;
    this.serverTime = serverTime;
    this.debugMode = debugMode;
    super.totalLength = (short) (HEAD_LENGTH + BODY_LENGTH);
    super.commandId = DeviceCommand.LOGIN_RESP;
    super.sequenceId = sequenceId;
    super.packetName = PACKET_NAME;
  }

  @Override
  public byte[] getPacketBody()
  {
    return ByteHelper.margeByte(new byte[] { loginResult }, new byte[] { debugMode }, ByteHelper.intToByteArray(serverTime), serverVer.getBytes(),null, null, null, null, null, null);
  }

  public static void main(String[] args)
  {

  }

  @Override
  public void makeBody()
  {

  }

  public byte getLoginResult()
  {
    return loginResult;
  }

  public void setLoginResult(byte loginResult)
  {
    this.loginResult = loginResult;
  }

  public long getServerTime()
  {
    return serverTime;
  }

  public void setServerTime(int serverTime)
  {
    this.serverTime = serverTime;
  }

  public String getServerVer()
  {
    return serverVer;
  }

  public void setServerVer(String serverVer)
  {
    this.serverVer = serverVer;
  }

  public byte getDebugMode()
  {
    return debugMode;
  }

  public void setDebugMode(byte debugMode)
  {
    this.debugMode = debugMode;
  }

}
